//
//  ZQOAuthViewController.swift
//  Sina Blog
//
//  Created by 张强 on 16/5/11.
//  Copyright © 2016年 张强. All rights reserved.
//

import UIKit

class ZQOAuthViewController: UIViewController {

  private let blogAppKey = "2662689608"
    
  private  let blogRedirecturi = "http://www.baidu.com"
    
    private lazy var webView = UIWebView()
    
    
    override func loadView() {
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        view.backgroundColor = UIColor.whiteColor()
        let url = "https://api.weibo.com/oauth2/authorize?client_id=\(blogAppKey)&redirect_uri=\(blogRedirecturi)"
        let request = NSURLRequest(URL: NSURL(string: url)!)
        webView.loadRequest(request)
        
        
        // Do any additional setup after loading the view.
    }
    
    private func setupUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "取消", style: .Plain, target: self, action: #selector(cancelClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "自动登陆", style: .Plain, target: self, action: #selector(autoFill))
        navigationItem.title = "微博登录"
    
    }
    
    @objc func cancelClick() {
    
     dismissViewControllerAnimated(true, completion: nil)
    
    }
    @objc func autoFill() {
       
    
webView.stringByEvaluatingJavaScriptFromString("document.getElementById('userId').value = '784667483@qq.com'; document.getElementById('passwd').value = 'zhangqiang1989'")
    
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

   
}
